//设置默认值
function defaultSet(para,val)
{
	if(para == null || typeof(para) == 'undefined' || para == '')
	{
		para = val;
	}
	return para;
}

//输入非空
function isEmpty(val)
{
	if($.trim(val) == '')
	{
		return true;
	}
	return false;
}

//input输入校验,默认为模型名称
function inputChk(id,name,len)
{
	name = defaultSet(name,"姓名");
	len = defaultSet(len,50);
	
	var val = $('#'+id).val();
	if(isEmpty(val))
	{
		return name + "不能为空";
	}else if(outLength(val,len))
	{
		return name + "可输入最大长度为" + len;
	}else{
		return '';
	}
}

function inputChkAllowEmpty(id,name,len){
	var val = $('#'+id).val();
	if(isEmpty(val)){
		return '';
	}else{
		var length = val.length();
		if(outLength(val,len)){
			return name + "可输入最大长度为" + len;
		}else{
			return '';
		}
	}
}

//输入长度限制
function outLength(str,len)
{
	var length = str.length;
	if(length > len)
	{
		return true;
	}
	return false;
}

function checkTel(id,ifEmpty){
	var val = $('#'+id).val();
	if(ifEmpty && isEmpty(val)){
		return '';
	}else{
		var reg = /^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/;
		if(!reg.test(val)){
			return "电话格式不对";
		}else{
			return '';
		}
	}
}

function checkMobile(id,ifEmpty){
	var val = $('#'+id).val();
	if(ifEmpty && isEmpty(val)){
		return '';
	}else{
		var reg = /^(\d{11})$/;
		//var reg = /^(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/;
		if(!reg.test(val)){
			return "手机格式不对";
		}else{
			return '';
		}
	}
}

function checkEmail(id,ifEmpty){
	var val = $('#'+id).val();
	if(ifEmpty && isEmpty(val)){
		return '';
	}else{
		var reg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		if(!reg.test(val)){
			return "电子邮箱格式不对";
		}else{
			return '';
		}
	}
}

function checkPost(id,ifEmpty){
	var val = $('#'+id).val();
	if(ifEmpty && isEmpty(val)){
		return '';
	}else{
		var reg = /^[0-9]{6}$/;
		if(!reg.test(val)){
			return "邮编格式不对";
		}else{
			return '';
		}
	}
}